package kr.co.sdsway2.web.client;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.sdsway2.comm.SdsWay2Util;
import kr.co.sdsway2.service.RemoconService;
import kr.co.sdsway2.vo.AvatarVO;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class RemoconController  implements Controller {
protected final Log logger = LogFactory.getLog(getClass());
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest req,
			HttpServletResponse res) throws Exception {
	
		logger.info("┌──────────────────────────────────────Returning hello view───────────────────────────────────────────────┐");
		SdsWay2Util.printReq(req,logger);
		logger.info("└──────────────────────────────────────Returning hello view───────────────────────────────────────────────┘");
		
//		String avatarId = req.getParameter("avatarId");
		String avatarId = "01085177411";
		String direction =	req.getParameter("direction");
		String distance = req.getParameter("distance");
			
		RemoconService service = new RemoconService();
//		AvatarVO avatarVO = dao.selectAvatarByPk(avatarId);
		
		if(	direction!=null && !"".equals(direction) && 
			distance!=null && !"".equals(distance) &&
			service.isAvatarExist(avatarId)){
			service.updatePosition(avatarId,direction,distance);
		}
		
		AvatarVO avatarVO = service.getAvatarPosition(avatarId);
		req.setAttribute("avatarVO", avatarVO);
		
		ModelAndView mav = new ModelAndView("remocon.jsp");
        mav.addObject("avatarVO", avatarVO);
        
		return mav;
	}
}
